<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>视频查看</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody videoList"
           v-loading="videoloading"
           element-loading-text="加载中"
           element-loading-spinner="iconfont iconluzhishipin"
           element-loading-background="rgba(0, 0, 0, 0.5)">
<!--        <video :src="srcOption" id="videoLog">-->
<!--        </video>-->
        <video-player
          class="video-player vjs-custom-skin videoLog"
          ref="videoPlayer"
          :options="playerOptions"
          :playsinline="true">
        </video-player>
      </div>
      <div class="cornerComment-in-footer">
        <el-button size="small" @click="closePOpup">退出</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {mapGetters} from "vuex";

export default {
  props: ['visible', 'videoSrc'],
  components: {},
  computed: {
    ...mapGetters(['configData']),
  },
  data() {
    return {
      dialogVisible: false,
      start: false,
      time: null,
      h: 0,//定义时，分，秒，毫秒并初始化为0；
      m: 0,
      ms: 0,
      s: 0,
      str: '00:00:00',
      cameraUrl: '', // 播放地址
      videoloading: true,
      disabledBtn: false,
      cameraIndex: 0, // 序列号
      camera_socketIndex: 0,
      recordIndex: 0,
      // 0 待接入 1 开启中
      status: {
        index: 0,
        socketIndex: 0,
        recordIndex: 0,
      },
      srcOption: '',
      playerOptions: {
        playbackRates: [0.5, 1.0, 1.5, 2.0], // 可选的播放速度
        autoplay: false, // 如果为true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 是否视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [{
          type: "video/mp4", // 类型
          src: '' // url地址
        }],
        poster: '', // 封面地址
        notSupportedMessage: '此视频暂无法播放，请稍后再试', // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: true, // 当前时间和持续时间的分隔符
          durationDisplay: true, // 显示持续时间
          remainingTimeDisplay: false, // 是否显示剩余时间功能
          fullscreenToggle: true // 是否显示全屏按钮
        }
      }
    }
  },
  watch: {
    visible() {
      let that = this
      this.dialogVisible = this.visible
      if (this.visible) {
        this.playerOptions.sources[0].src = `${this.configData.video_url}${this.videoSrc}`
        console.log('数据：', `${this.configData.video_url}${this.configData.keep_port?':'+this.configData.keep_port:''}/${this.videoSrc}`)
        this.srcOption = `${this.configData.video_url}${this.videoSrc}`
        setTimeout(() => {
          that.videoloading = false
        }, 500)
      } else {
        this.playerOptions.sources[0].src = ""
        this.srcOption = ''
        this.videoloading = true
      }
    }
  },
  created() {
  },
  methods: {
    // 关闭弹窗
    closePOpup() {
      this.playerOptions.sources[0].src = ""
      this.$emit('update:visible', false)
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.2) !important;
  /*background:none;*/
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  background: rgba(47, 48, 74, 0.8);
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  border: 1px solid #003156;
  box-shadow: 0 0 10px #002f52;
  height: auto;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
  color: #fff;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  /*padding: 20px;*/
  flex: 1;
  overflow-y: auto;
  position: relative;
  background: #000;
}

.close-Btn-line {
  cursor: pointer;
}

#videoLine {
  width: 816px;
  height: 466px;
  background: rgba(0, 0, 0, .5);
}

#iframeBox {
  width: 100%;
  height: 100%;
}

.camera-top {
  height: 100%;
  background: #999;
}

.camera-bottom {
  position: absolute;
  top: 0;
  width: 100%;
  left: 0;
  display: flex;
  padding: 15px 0;
  align-items: center;
  justify-content: center;
}

.camera-bottom span {
  background: red;
  color: #fff;
  display: block;
  width: 80px;
  padding: 5px 0;
  text-align: center;
  font-size: 16px;
  border-radius: 3px;
}

.camera-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.camera-icon i {
  margin: 0;
  font-size: 64px;
  color: #eee;
}
.video-player{
  height: 100%;
}
.iframeBody{
  width: 100%;
  height: 400px;
}
.videoLog{
  height: 500px;
  width: 750px;
}
</style>

